//
//  ViewController.m
//  04-HomeWork
//
//  Created by dllo on 16/7/19.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#import "Button_image.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#define kWidth self.view.bounds.size.width
#define kHeight self.view.bounds.size.height
#import "Masonry.h"
@interface ViewController ()
@property (nonatomic, strong) UIImageView *backGroundImage;
@property (nonatomic, strong) Button_image *normButton;
@property (nonatomic, strong) Button_image *exclusiveButton;
@property (nonatomic, strong) Button_image *MVButton;
@property (nonatomic, strong) Button_image *dtsButton;
@property (nonatomic, strong) Button_image *leftButton;
@property (nonatomic, strong) Button_image *middleButton;
@property (nonatomic, strong) Button_image *rightButton;

@property (nonatomic, strong) Button_image *heartButton;
@property (nonatomic, strong) Button_image *cycleButton;
@property (nonatomic, strong) Button_image *downloadeButton;
@property (nonatomic, strong) Button_image *saveButton;
@property (nonatomic, strong) Button_image *collectButton;

@property (nonatomic, strong) Button_image *pullButton;

@property (nonatomic, strong) Button_image *pointButton;

@property (nonatomic, strong) UIImageView *circleImage;
@property (nonatomic, strong) UIImageView *middleImage;
@property (nonatomic, strong) UILabel *labelSong;
@property (nonatomic, strong) UILabel *labelSinger;
@property (nonatomic, strong) UILabel *labelSoneName;
@property (nonatomic, strong) UILabel *leftLabel;
@property (nonatomic, strong) UILabel *rightLabel;
@property (nonatomic, strong) UISlider *slider;
@property (nonatomic, strong) UIPageControl *pageControl;




@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self createBackGround];
    [self createImageButton];
    [self createCircleImage];
    [self createLabelAndPageControl];
    [self createSlider];
    [self createPlayImageView];
    [self createDownImage];
    [self createButton];
    
}
#pragma mark - 创建背景图片和label和view
- (void)createBackGround {
    // 创建背景
    self.backGroundImage = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _backGroundImage.image = [UIImage imageNamed:@"profile_homepage_default_bg"];
    [self.view addSubview:_backGroundImage];
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    view.backgroundColor = [UIColor colorWithRed:0.39 green:0.36 blue:0.32 alpha:0.8];
    [_backGroundImage addSubview:view];
    // 创建label
    self.labelSong = [[UILabel alloc] init];
    self.labelSinger = [[UILabel alloc] init];
    self.labelSong.text = @"稻香";
    self.labelSinger.text = @"周杰伦";
    self.labelSong.textColor = [UIColor whiteColor];
    self.labelSinger.textColor = [UIColor whiteColor];
    self.labelSong.font = [UIFont systemFontOfSize:30];
    self.labelSinger.font = [UIFont systemFontOfSize:22];
    [self.view addSubview:self.labelSinger];
    [self.view addSubview:self.labelSong];
    [self.labelSong mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).multipliedBy(1 / 7.0f);
    }];
    [self.labelSinger mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.labelSong);
        make.topMargin.equalTo(self.labelSong.bottom).offset(20);
    }];
    // 创建线view
    UIView *viewLineLeft = [[UIView alloc] init];
    UIView *viewLineRight = [[UIView alloc] init];
    viewLineLeft.backgroundColor = [UIColor whiteColor];
    viewLineRight.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewLineLeft];
    [self.view addSubview:viewLineRight];
    [viewLineLeft makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labelSinger);
        make.right.equalTo(self.labelSinger.left).equalTo(- 10);
        make.width.equalTo(self.labelSinger.width).multipliedBy(1 / 2.0f);
        make.height.equalTo(1);
    }];
    [viewLineRight makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labelSinger);
        make.left.equalTo(self.labelSinger.right).equalTo(10);
        make.width.equalTo(self.labelSinger.width).multipliedBy(1 / 2.0f);
        make.height.equalTo(1);
    }];
}
#pragma mark - 创建标题栏那些button
- (void)createImageButton {
    self.normButton = [Button_image buttonWithType:UIButtonTypeSystem];
    self.exclusiveButton = [Button_image buttonWithType:UIButtonTypeSystem];
    self.MVButton = [Button_image buttonWithType:UIButtonTypeSystem];
    self.dtsButton = [Button_image buttonWithType:UIButtonTypeSystem];
    
    _normButton.frame = CGRectMake(60, 140, 80, 30);
    _exclusiveButton.frame = CGRectMake(150, 140, 60, 30);
    _MVButton.frame = CGRectMake(220, 140, 60, 30);
    _dtsButton.frame = CGRectMake(290, 140, 60, 30);
    
    [_normButton setImage:[[UIImage imageNamed:@"player_btn_bz_sel_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_exclusiveButton setImage:[[UIImage imageNamed:@"player_btn_copyright_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_MVButton setImage:[[UIImage imageNamed:@"player_btn_mv_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_dtsButton setImage:[[UIImage imageNamed:@"player_btn_dts_on"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [self.view addSubview:_normButton];
    [self.view addSubview:_exclusiveButton];
    [self.view addSubview:_MVButton];
    [self.view addSubview:_dtsButton];
    [_normButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view).multipliedBy(80/ kWidth);
        make.height.equalTo(self.view).multipliedBy(30 / kHeight);
        make.left.equalTo(self.view.left).equalTo((kWidth * (1 - 80 / kWidth - 3 * 60 / kWidth) - 60) / 2.0f);
        make.top.equalTo(self.labelSinger.bottom).equalTo(20);
        
    }];
    [_exclusiveButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view).multipliedBy(60/ kWidth);
        make.height.equalTo(self.view).multipliedBy(30 / kHeight);
        make.left.equalTo(_normButton.right).equalTo(20);
        make.centerY.equalTo(_normButton.centerY);
    }];
    [_MVButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view).multipliedBy(60/ kWidth);
        make.height.equalTo(self.view).multipliedBy(30 / kHeight);
        make.left.equalTo(_exclusiveButton.right).equalTo(20);
        make.centerY.equalTo(_exclusiveButton.centerY);
    }];
    [_dtsButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view).multipliedBy(60/ kWidth);
        make.height.equalTo(self.view).multipliedBy(30 / kHeight);
        make.left.equalTo(_MVButton.right).equalTo(20);
        make.centerY.equalTo(_MVButton.centerY);
    }];
    
}
#pragma mark - 创建中间圆图片
- (void)createCircleImage {
    // 创建底层图片
    self.circleImage = [[UIImageView alloc] init];
    
    _circleImage.layer.cornerRadius = kHeight * (300 / kHeight) / 2;
    _circleImage.image = [UIImage imageNamed:@"player_icon_mvPreview"];
    _circleImage.layer.masksToBounds = YES;
    [self.view addSubview:_circleImage];
    // 创建中间图片
    self.middleImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"text_style_chs_10"]];
    [self.view addSubview:_middleImage];
    _middleImage.layer.cornerRadius = kHeight * (280 / kHeight) / 2;
    _middleImage.center = _circleImage.center;
    _middleImage.layer.masksToBounds = YES;
    [_circleImage makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.view.height).multipliedBy(300 / kHeight);
        make.width.equalTo(self.view.height).multipliedBy(300 / kHeight);
//        make.centerY.equalTo(self.view).multipliedBy(8 / 9.0f);
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.MVButton.bottom).equalTo(20);
    }];
    [_middleImage makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.view.height).multipliedBy(280 / kHeight);
        make.width.equalTo(self.view.height).multipliedBy(280 / kHeight);
        make.centerY.equalTo(_circleImage);
        make.centerX.equalTo(_circleImage);

    }];

}
#pragma mark - 创建图片下的label和pagecontrol
- (void)createLabelAndPageControl {
    // 创建label
    self.labelSoneName = [[UILabel alloc] init];
    [self.view addSubview:_labelSoneName];
    _labelSoneName.text = @"曲: 周杰伦";
    _labelSoneName.textColor = [UIColor whiteColor];
    _labelSoneName.font = [UIFont systemFontOfSize:22];
    // 创建pageControl
    self.pageControl = [[UIPageControl alloc] init];
    [self.view addSubview:_pageControl];
    _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    _pageControl.numberOfPages = 3;
    [_labelSoneName makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.circleImage.bottom).equalTo(20);
        make.centerX.equalTo(self.view);
    }];
    [_pageControl makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labelSoneName.bottom).equalTo(0);
        make.centerX.equalTo(self.view);
    }];
    
}
#pragma mark - 创建slider
- (void)createSlider {
    // 创建slider
    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(60, 560, 294, 20)];
    [_slider setMinimumTrackImage:[UIImage imageNamed:@"player_slider_playback_left"] forState:UIControlStateNormal];
    [_slider setThumbImage:[UIImage imageNamed:@"player_slider_playback_thumb"] forState:UIControlStateNormal];
    [self.view addSubview:_slider];
    //创建左边的label
    self.leftLabel = [[UILabel alloc] init];
    [self.view addSubview:_leftLabel];
    _leftLabel.textColor = [UIColor whiteColor];
    _leftLabel.text = @"00:13";
    //创建右边的label
    self.rightLabel = [[UILabel alloc] init];
    [self.view addSubview:_rightLabel];
    _rightLabel.textColor = [UIColor whiteColor];
    _rightLabel.text = @"03:13";
    [self.slider makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pageControl.bottom).equalTo(0);
        make.width.equalTo(self.view.width).multipliedBy(270 / kWidth);
        make.centerX.equalTo(self.view);
    }];
    [self.leftLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.slider);
        make.right.equalTo(self.slider.left).equalTo(-10);
        
    }];
    [self.rightLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.slider);
        make.left.equalTo(self.slider.right).equalTo(10);
    }];

}
#pragma mark - 创建播放的button
- (void)createPlayImageView {
    self.leftButton = [Button_image buttonWithType:UIButtonTypeSystem];
    self.middleButton = [Button_image buttonWithType:UIButtonTypeSystem];
    self.rightButton = [Button_image buttonWithType:UIButtonTypeSystem];
    
//    _leftButton.frame = CGRectMake(60, 590, 90, 90);
//    _middleButton.frame = CGRectMake(160, 590, 90, 90);
//    _rightButton.frame = CGRectMake(265, 590, 90, 90);
    
    [_leftButton setImage:[[UIImage imageNamed:@"hp_player_btn_pre_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_middleButton setImage:[[UIImage imageNamed:@"player_btn_pause_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [_rightButton setImage:[[UIImage imageNamed:@"hp_player_btn_next_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    
    
    [self.view addSubview:_leftButton];
    [self.view addSubview:_rightButton];
    [self.view addSubview:_middleButton];
    [self.middleButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.slider.bottom).equalTo(8);
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view.width).multipliedBy(80 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(80 / kWidth);
    }];
    [self.leftButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.middleButton);
        make.height.equalTo(self.middleButton);
        make.centerY.equalTo(self.middleButton);
        make.right.equalTo(self.middleButton.left).equalTo(-40);
    }];
    [self.rightButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.middleButton);
        make.height.equalTo(self.middleButton);
        make.centerY.equalTo(self.middleButton);
        make.left.equalTo(self.middleButton.right).equalTo(40);
    }];
    
}
#pragma mark - 创建提示图片
- (void)createDownImage {
    self.heartButton = [Button_image buttonWithType:UIButtonTypeCustom];
    [_heartButton setImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];
    self.cycleButton = [Button_image buttonWithType:UIButtonTypeCustom];
    [_cycleButton setImage:[UIImage imageNamed:@"2"] forState:UIControlStateNormal];
    self.downloadeButton = [Button_image buttonWithType:UIButtonTypeCustom];
    [_downloadeButton setImage:[UIImage imageNamed:@"4"] forState:UIControlStateNormal];
    self.saveButton = [Button_image buttonWithType:UIButtonTypeCustom];
    [_saveButton setImage:[UIImage imageNamed:@"3"] forState:UIControlStateNormal];
    self.collectButton = [Button_image buttonWithType:UIButtonTypeCustom];
    [_collectButton setImage:[UIImage imageNamed:@"5"] forState:UIControlStateNormal];
//    _heartButton.frame = CGRectMake(10, 665, 30, 30);
//    _cycleButton.frame = CGRectMake(90, 665, 30, 30);
//    _downloadeButton.frame = CGRectMake(170, 665, 30, 30);
//    _saveButton.frame = CGRectMake(250, 665, 30, 30);
//    _collectButton.frame = CGRectMake(330, 665, 30, 30);
    
    [self.view addSubview:_heartButton];
    [self.view addSubview:_cycleButton];
    [self.view addSubview:_downloadeButton];
    [self.view addSubview:_saveButton];
    [self.view addSubview:_collectButton];
    [self.downloadeButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(30 / kWidth);        make.bottom.equalTo(self.view.bottom).equalTo(-10);
    }];
    [self.cycleButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.downloadeButton);
        make.width.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.centerX.equalTo(self.view).multipliedBy(3 / 5.0f);
    }];
    [self.heartButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.downloadeButton);
        make.width.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.centerX.equalTo(self.view).multipliedBy(1 / 5.0f);

    }];
    [self.saveButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.downloadeButton);
        make.width.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.centerX.equalTo(self.view).multipliedBy(7 / 5.0f);
    }];
    [self.collectButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.downloadeButton);
        make.width.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.height.equalTo(self.view.width).multipliedBy(30 / kWidth);
        make.centerX.equalTo(self.view).multipliedBy(9 / 5.0f);
    }];
   
}
#pragma mark - 创建下拉按钮和点点点按钮
- (void)createButton {
    // 创建下拉的button
    self.pullButton = [Button_image buttonWithType:UIButtonTypeSystem];
    [_pullButton setImage:[UIImage imageNamed:@"miniplayer_btn_playlist_close"] forState:UIControlStateNormal];
    _pullButton.tintColor= [UIColor whiteColor];
    [self.view addSubview:_pullButton];
    // 创建点点button
    self.pointButton = [Button_image buttonWithType:UIButtonTypeSystem];
    
    [_pointButton setImage:[UIImage imageNamed:@"dlna_more_devices"] forState:UIControlStateNormal];
    _pointButton.tintColor= [UIColor whiteColor];
    [self.view addSubview:_pointButton];
    
    [self.pullButton makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view.height).multipliedBy(40 / kHeight);
        make.height.equalTo(self.view.height).multipliedBy(40 / kHeight);
        make.centerY.equalTo(self.labelSong);
        make.centerX.equalTo(self.view).multipliedBy(1/ 4.0f);

    }];
    
    [self.pointButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view.height).multipliedBy(35 / kHeight);
        make.height.equalTo(self.view.height).multipliedBy(35 / kHeight);
        make.centerY.equalTo(self.labelSong);
        make.centerX.equalTo(self.view).multipliedBy(7 / 4.0f);

    }];
    

}
















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
